;(function($){
    $.fn.electron_upload = function(opts){
        var el = this;
        var opt = {
            url : "",
            data : "",
            muliFiles : false,//是否多文件上传
            fileElementId : "avatar1",
            dataBack : function(){},
        }
        var param = $.extend(opt,opts);
        var eu = new electron_upload(el,param);
    }

    var electron_upload = function(el,param){
        this.el = el;
        this.param = param;
        this.init();
    }
    electron_upload.prototype = {
        init : function(){
            var el = this.el;
            var param = this.param;

            var formData = new FormData();
            //⑤获取传入元素的val
            var name = $("#"+param.fileElementId).val();
            //⑥获取files
            var files = $("#"+param.fileElementId)[0].files[0];//
            if(param.muliFiles){
                var files = $("#"+param.fileElementId)[0].files;
                for(var i=0;i<files.length;i++){
                    formData.append("avatar", files[i],files[i].name);
                }
            }else{
                formData.append("avatar", files);
            }
            //⑦将name 和 files 添加到formData中，键值对形式
        
            if(param.data){
                for(var key in param.data){
                    formData.append(key, param.data[key]); 
                }
            }
            $.ajax({
                url: param.url,
                type: 'POST',
                data: formData,
                processData: false,// ⑧告诉jQuery不要去处理发送的数据
                contentType: false, // ⑨告诉jQuery不要去设置Content-Type请求头
                success: function (responseStr) {
                    param.dataBack(responseStr);
                },
                error : function (responseStr) {
                    param.errBack(responseStr);
                }
            });

        },
    }
})(jQuery);